
# Create your views here.
from django.shortcuts import render
from django.template import loader
from django.utils import timezone
from django.http import Http404
from django.views import generic
from django.shortcuts import get_object_or_404
from .cores import *
from django.http import HttpResponse, HttpResponseRedirect
from .models import Employ,scorer,question,Department,time


import datetime

import xlwt

from apscheduler.schedulers.blocking import BlockingScheduler





#ast.literal_eval(str)


i=1
GENDER_CHOICES_DEPART={
		'管理员':0,
		'书记':1,
		'院长':2,
		'院领导':3,
		'部门负责人':4,
		'其他中层':5,
		'专职教师':6,
		'辅导员':7,
		'普通职工':8,
}

GENDER_CHOICES_DEPARTnumber=dict(zip(GENDER_CHOICES_DEPART.values(),GENDER_CHOICES_DEPART.keys()))
#辅导员36
GRADE_CRITERUON={
    '辅导员':
        {'max':7,'min':1},
    '专职教师':
        {'max': 35, 'min': 18},
    '普通职工':
        {'max': 12, 'min': 8},
    '其他中层':
        {'max': 17, 'min': 13},
}

depart_weight={
    '院长':0.2,
    '书记':0.2,
    '辅导员':0.05,
    '专职教师':0.05,
    '主管院领导':0.2,
    '中层互评':0.1,
}

#异步调度


class job_setter():

    def __init__(self):

        self.sched = BlockingScheduler()
        self.job_list = [];
    def start(self):
        self.sched.start()
    def new_job(self,time):
        job_id = self.sched.add_job(when_time_to_end_crawler_job, 'date', run_date=time)
        self.job_list.append(job_id);
    def remove_job(self):
        for obj in self.job_list:
            obj.remove();

job_process=job_setter()





#test
def tosave():
    print("no more bug");

def get_auth_grade(user):
    if(user.employ_auth==7):
        context=question.objects.filter(question_belong='辅导员')
    elif(user.employ_auth==6):
        context = question.objects.filter(question_belong='专职教师')
    elif(user.employ_auth==8):
        context = question.objects.filter(question_belong='普通职工')
    elif(user.employ_auth==5):
        context = question.objects.filter(question_belong='中层')
    else:
        context = question.objects.filter(question_belong='中层')

    return context


#详细评价
def toevaluate(request,appraiser,appraisered):
    user = Employ.objects.get(employ_ID=appraiser)
    user1 = Employ.objects.get(employ_ID=appraisered)

    context={'apperaiser':user,'appraisered':user1}

    que=get_auth_grade(user1)
    context['question']=que
    return render(request, 'empoll/apperaiser.html', context)

#详细评价错误端口
def to(request):
    context={}
    return render(request,'empoll/apperaiser.html',context)



def getcommintlist(id):
    user = Employ.objects.get(employ_ID=id)
    if (user.employ_auth == 0):
        all_list = Employ.objects.all().exclude(employ_ID=id).order_by('employ_auth')
    elif (user.employ_auth == 1):
        all_list = Employ.objects.filter(employ_auth__lt=9, employ_auth__gt=0).exclude(employ_ID=id).order_by(
            'employ_auth')
    elif (user.employ_auth == 2):
        all_list = Employ.objects.filter(employ_auth__lt=9, employ_auth__gt=1).exclude(employ_ID=id).order_by(
            'employ_auth')
    elif (user.employ_auth == 3):
        all_list = Employ.objects.filter(employ_auth__lt=9, employ_auth__gt=2).exclude(employ_ID=id).order_by(
            'employ_auth')
    else:
        all_list = Employ.objects.filter(employ_auth__lte=8, employ_auth__gte=4).exclude(employ_ID=id).order_by(
            'employ_auth')
    return all_list

#管理员管理所有用户列表
def touserlist(request,id):
    alluser=Employ.objects.all().exclude(employ_ID=id).order_by('employ_auth')
    user=Employ.objects.get(employ_ID=id)
    all_list=getcommintlist(id)
    b = str(user.employ_has)
    b = b.split(',')
    context={'employ_list':alluser,'latest_Empoly_list':user,'all_employ_list':all_list,'employhas':b}
    return render(request,'empoll/userlist.html',context)

#登录模块
def login(request,user_id=None):
    return render(request, 'empoll/login.html')
#登录模块不需要验证
def loginwithoutvalite(request,id):
    user = Employ.objects.get(employ_ID=id)
    context={}
    if (user.employ_auth == 0):
        all_list = Employ.objects.all().exclude(employ_ID=id).order_by('employ_auth')
    elif (user.employ_auth == 1):
        all_list = Employ.objects.filter(employ_auth__lt=9, employ_auth__gt=0).exclude(employ_ID=id).order_by('employ_auth')
    elif (user.employ_auth == 2):
        all_list = Employ.objects.filter(employ_auth__lt=9, employ_auth__gt=1).exclude(employ_ID=id).order_by('employ_auth')
    elif (user.employ_auth == 3):
        all_list = Employ.objects.filter(employ_auth__lt=9, employ_auth__gt=2).exclude(employ_ID=id).order_by('employ_auth')
    else:
        all_list = Employ.objects.filter(employ_auth__lte=8, employ_auth__gte=4).exclude(employ_ID=id).order_by('employ_auth')

    depart_list, depart_no_list = getleader_manage_people(id)


    b = str(user.employ_has)
    b = b.split(',')
    timeo = time.objects.get(id=1)

    if (user.employ_auth >= 1 and user.employ_auth <= 2):
        context = {'latest_Empoly_list': user, 'all_employ_list': all_list, 'employhas': b, 'time': timeo,
                       'has_else_msg': '*分数超过95分的不能超过所以被打分对象的50%'}
    elif (user.employ_auth == 3 and user.employ_name != '段其旺'):
        context = {'latest_Empoly_list': user, 'all_employ_list': all_list, 'employhas': b, 'time': timeo,
                       'has_else_msg': '*对于您的主管的部门人员以及非主管部门人员，给这两类打分时，每一类中分数大于等于95分的均不能超过50%'}
    else:
        context = {'latest_Empoly_list': user, 'all_employ_list': all_list, 'employhas': b, 'time': timeo}
    context['wang'] = depart_list[0]
    context['wang_ed'] = depart_no_list[0]
    context['li'] = depart_list[1]
    context['li_ed'] = depart_no_list[1]
    context['zhang'] = depart_list[2]
    context['zhang_ed'] = depart_no_list[2]
    context['jin'] = depart_list[3]
    context['jin_ed'] = depart_no_list[3]
    context['has_else_msg'] = '注意您的打分中95分及以上不能超过您对该组的整体评分中的50%'
    return render(request, 'empoll/index.html', context)
    context = {'latest_Empoly_list': user, 'all_employ_list': all_list, 'employhas': b, 'time': timeo}
    return render(request, 'empoll/index.html', context)

#登录需要验证
def loginin(request):
    context={}
    try:
        id = request.POST['id']
        seret = eval(request.POST['seret'])
        user = Employ.objects.get(employ_ID=id)
        if(user.employ_auth==0):
            all_list=Employ.objects.all().exclude(employ_ID=id).order_by('employ_auth')
        elif(user.employ_auth==1):
            all_list=Employ.objects.filter(employ_auth__lte=8, employ_auth__gte=4).exclude(employ_ID=id).order_by('employ_auth')
        elif(user.employ_auth==2):
            all_list = Employ.objects.filter(employ_auth__lte=8, employ_auth__gte=4).exclude(employ_ID=id).order_by('employ_auth')
        elif(user.employ_auth==3):
            all_list = Employ.objects.filter(employ_auth__lte=8, employ_auth__gte=4).exclude(employ_ID=id).order_by('employ_auth')
        else:
            all_list = Employ.objects.filter(employ_auth__lte=8, employ_auth__gte=4).exclude(employ_ID=id).order_by('employ_auth')
        depart_list,depart_no_list=getleader_manage_people(id)

    except:
        return render(request, 'empoll/error.html', {'error_msg': '请输入正确的工号和密码！','id':None})
    else:
        if user.employ_login==seret:
            b = str(user.employ_has)
            b=b.split(',')
            timeo=time.objects.get(id=1)
            nowtime=eval(datetime.datetime.now().strftime('%Y%m%d%H'))

            st=eval(timeo.time_start.strftime('%Y%m%d%H'))+8
            et=eval(timeo.time_end.strftime('%Y%m%d%H'))+8

            if not user.employ_auth:
                context = {'latest_Empoly_list': user, 'all_employ_list': all_list, 'employhas': b, 'time': timeo}
                context['wang'] = depart_list[0]
                context['wang_ed'] = depart_no_list[0]
                context['li'] = depart_list[1]
                context['li_ed'] = depart_no_list[1]
                context['zhang'] = depart_list[2]
                context['zhang_ed'] = depart_no_list[2]
                context['jin'] = depart_list[3]
                context['jin_ed'] = depart_no_list[3]
                context['has_else_msg'] = '注意您的打分中95分及以上不能超过您对该组的整体评分中的50%'
                return render(request, 'empoll/index.html', context)
            else:

                if(nowtime>st and nowtime <et ):
                    if(user.employ_auth>=1 and user.employ_auth<=2):
                        context = {'latest_Empoly_list': user, 'all_employ_list': all_list, 'employhas': b, 'time': timeo,
                                   'has_else_msg': '*分数超过95分的不能超过所以被打分对象的50%'}
                    elif (user.employ_auth == 3 and user.employ_name != '段其旺'):
                        context={'latest_Empoly_list': user,'all_employ_list':all_list,'employhas':b,'time':timeo,'has_else_msg':'*对于您的主管的部门人员以及非主管部门人员，给这两类打分时，每一类中分数大于等于95分的均不能超过50%'}
                    else:
                        context = {'latest_Empoly_list': user,'all_employ_list':all_list,'employhas':b,'time':timeo}
                    context['wang'] = depart_list[0]
                    context['wang_ed'] = depart_no_list[0]
                    context['li'] = depart_list[1]
                    context['li_ed'] = depart_no_list[1]
                    context['zhang'] = depart_list[2]
                    context['zhang_ed'] = depart_no_list[2]
                    context['jin'] = depart_list[3]
                    context['jin_ed'] = depart_no_list[3]
                    context['has_else_msg']='注意您的打分中95分及以上不能超过您对该组的整体评分中的50%'
                    return render(request, 'empoll/index.html', context)
                elif nowtime<st:
                    return render(request, 'empoll/error.html', {'error_msg': '抱歉评教还未开始', 'id': None})
                else:
                    return render(request, 'empoll/error.html', {'error_msg': '抱歉已超过评教时间', 'id': None})
        else:
            return render(request, 'empoll/error.html', {'error_msg': '请输入正确的密码！','id':None})

#改变个人信息
def changeinfor(request,employ_id):
    user=Employ.objects.get(employ_ID=employ_id)
    context={'employ_info':user}
    return render(request, 'empoll/detail.html',context)
def change(request,employ_id):
    user=Employ.objects.get(employ_ID=employ_id)
    try:
       # name = request.POST['name']
       # de = request.POST['de']
        se = eval(request.POST['se'])
        if se <100000:
            return render(request, 'empoll/error.html', {'error_msg': '请输入正确格式的密码','id':employ_id})
    except:
        return render(request, 'empoll/error.html', {'error_msg': '输入出错','id':employ_id})
    else:
        user.employ_login=se
       # user.employ_name=name
       # user.employ_depart=de
        user.save()
        context={'employ_info':user}
        return loginwithoutvalite(request,employ_id)

#添加评论
def addscore(request,appraiser,appraisered):
    try:
        value = eval(request.POST['score_value'])
    except:
        return render(request, 'empoll/error.html', {'error_msg': '系统繁忙请稍后','id':appraiser})
    else:
        if scorer.objects.filter(scorer_appraiser=appraiser,scorer_appraisered=appraisered).first() != None:
            return render(request, 'empoll/error.html', {'error_msg': '已经对该成员进行评论了,无法再进行评论', 'id': appraiser})
        else:
            dic = {'scorer_appraiser':appraiser,'scorer_appraisered':appraisered,'scorer_value':value}
            scorer.objects.create(**dic)
            user = Employ.objects.get(employ_ID=appraiser)
            if user.employ_has==None:
                user.employ_has=','+appraisered
            else:
                user.employ_has+=','+appraisered
            user.save()

        return loginwithoutvalite(request,appraiser)

def addscoreall(request,id):
    user = Employ.objects.get(employ_ID=id)
    score_value=str(request.POST['score_value']).replace('\'','').split(',')
    score_app=str(request.POST['score_appraisered']).replace('\'','').split(',')
    dep=Employ.objects.filter(employ_ID=score_app[0]).first().employ_depart
    witch_depart=[]
    for i in manage_depart:
        if dep in manage_depart[i]:
            witch_depart=i
            break;

    context = '您已成功评论该组所有人'
    #print(score_value)
    cout=0
    for i in range(len(score_value)):
        if(int(score_value[i])>=95):
            cout+=1
    if(cout>int(len(score_value)/2)):
        context = '评论失败,您的评论中对所在部门的超过95分的评论数量不能超过所占全部人员的50%'
    else:
        for i in range(len(score_app)):
            if scorer.objects.filter(scorer_appraiser=id, scorer_appraisered= score_app[i]).first() == None:
                dic = {'scorer_appraiser': id, 'scorer_appraisered':  score_app[i],'scorer_value': score_value[i]}
                scorer.objects.create(**dic)
                if user.employ_has == None:
                    user.employ_has = ',' + score_app[i]
                else:
                    user.employ_has += ',' + score_app[i]
        user.save()

    return HttpResponse(context)

#管理员修改个人信息
def adminchange(request,id,id2):
    dic={}
    try:
        user=Employ.objects.get(employ_ID=id2)
        admin=Employ.objects.get(employ_ID=id)
        if(admin.employ_auth<=user.employ_auth):
            return render(request, 'empoll/error.html', {'error_msg': '您的权限不足以修改要修改用户的权限','id':id})
        if 'name' in request.POST:
            dic['name']= request.POST['name']
        if 'auth' in request.POST:
            dic['auth'] = request.POST['auth']
            dic['auth'] = GENDER_CHOICES_DEPART[dic['auth']]
        if 'de' in request.POST:
            dic['de'] = request.POST['de'].replace(' ','').replace('\n','')
        if 'is' in request.POST:
            dic['ismiddle'] = request.POST['is']

        if 'serect_key' in request.POST:
            dic['se'] = request.POST['serect_key']

    except:
        return render(request, 'empoll/error.html', {'error_msg': '请保证修改的各类信息是否正确','id':id})
    else:
        if('name' in dic):
            if(dic['name']!=''):
                user.employ_name=dic['name']
        if('auth' in dic):
            if (dic['auth'] != ''):
                user.employ_auth=dic['auth']
        if('de' in dic):
            if (dic['de'] != ''):
                user.employ_depart=dic['de']
        if('ismiddle' in dic):
            if (dic['ismiddle'] != ''):
                user.employ_ismiddle=eval(dic['ismiddle'])
        if('se' in dic):
            if (dic['se'] != ''):
                user.employ_login=eval(dic['se'])
        user.save()

        return touserlist(request,id)

#s管理员删除用户
def deleteEmploy(request,id,id2):

    employ_infor = get_object_or_404(Employ,employ_ID=id2)
    admin=get_object_or_404(Employ, employ_ID=id)
    if(8-employ_infor.employ_auth>=8-admin.employ_auth):
        return  render(request, 'empoll/error.html', {'error_msg': '您的权限不足以删除该用户','id':id})
    employ_infor.delete()

    return touserlist(request,id)



#管理员创建用户
def cemploy(request,id):
    dic={}
    try:
        dic['employ_name']= request.POST['name']
        dic['employ_auth'] = request.POST['auth']
        dic['employ_ID'] = request.POST['id']
        if Employ.objects.filter(employ_ID=dic['employ_ID']).first() != None:
            return render(request, 'empoll/error.html', {'error_msg': '已有ID', 'id': id})

        dic['employ_auth']=GENDER_CHOICES_DEPART[dic['employ_auth']]

        dic['employ_depart'] = request.POST['depart'].replace(' ','').replace('\n','')

        dic['employ_ismiddle'] = eval(request.POST['ismiddle'])

        dic['employ_login'] = eval(request.POST['se'])
    except:
        return render(request,'empoll/error.html',{'error_msg':'创建错误','id':id})
    else:
        Employ.objects.create(**dic)

        return touserlist(request,id)

#管理员查询个人用户
def search(request,id):
    try:
        id2=request.POST['q']
        user2=get_object_or_404(Employ,employ_ID=id2)
        user = get_object_or_404(Employ, employ_ID=id)
    except:
        return render(request, 'empoll/error.html', {'error_msg': '不存在该用户', 'id': id})
    else:

        context={'search':1,'obj1':user2,'latest_Empoly_list':user}
        return render(request,'empoll/userlist.html',context)

#评分消息列表
def commentlist(request,id):
    allinfor=scorer.objects.all().order_by('id')

    user=get_object_or_404(Employ,employ_ID=id)
    context = {'allinfor':allinfor,'latest_Empoly_list':user}
    return render(request,'empoll/commentlist.html',context)
#删除评分
def deletecomment(request,id,id2):
    user = get_object_or_404(Employ, employ_ID=id)
    mes=get_object_or_404(scorer,id=id2)
    stra=','+mes.scorer_appraisered
    chnageuser=get_object_or_404(Employ,employ_ID=mes.scorer_appraiser)
    chnageuser.employ_has=chnageuser.employ_has.replace(stra,'')
    chnageuser.save()
    mes.delete()
    allinfor = scorer.objects.all().order_by('id')
    context = {'allinfor': allinfor, 'latest_Empoly_list': user}
    return render(request,'empoll/commentlist.html',context)

#评分搜索
def commentsearch(request,id):
    user = get_object_or_404(Employ, employ_ID=id)
    try:
        idu=request.POST['q']
    except:
        return render(request, 'empoll/error.html', {'error_msg': '不存在该用户', 'id': id})
    cs=scorer.objects.filter(scorer_appraiser=idu)
    csed = scorer.objects.filter(scorer_appraisered=idu)
    allinfor = scorer.objects.all().order_by('id')
    context = {'allinfor': allinfor, 'latest_Empoly_list': user, 'search': cs, 'besearch': csed,'searcher':idu}
    if(cs.first()==None ):
        context['sen']=id+'还未评价他人'
    if(csed.first()==None):
        context['bsen']=id+'还未被他人评价'
    return render(request, 'empoll/commentlist.html', context)

#set_weight_value进入设置权值页面
def set_weight_value(request,id):
    department_name_list=[]
    for obj in Department.objects.all():
        if obj.Department_depart not in department_name_list:
            department_name_list.append(obj.Department_depart)
    context = {'id': id,'depart_name_list':department_name_list}
    return render(request, 'empoll/weight_set.html', context)
#打印所有
def toprint(request,id):
    context={'id':id}
    return render(request,'empoll/outputlist.html',context)

def  get_output_self_list(request,id):
    context = {'id': id}
    try:
        searchid = request.POST['q']
        context['search_id'] = searchid
        list = scorer.objects.filter(scorer_appraisered=searchid)
        user =Employ.objects.get(employ_ID=searchid)
    except:
        return render(request, 'empoll/error.html', {'error_msg': '查询ID不存在或者输入错误,请保证输入完整,若有问题请与管理员联系', 'id': id})
    total = 0
    employ_list=[]
    total = getgrade(user)
    if(total==None):
        return render(request,'empoll/error.html',{'error_msg': '请保证该ID号准则存在且唯一,若有问题请与管理员联系', 'id': id})
    '''
    for i in list:
        employ_list.append(GENDER_CHOICES_DEPARTnumber[Employ.objects.get(employ_ID=i.scorer_appraiser).employ_auth])
    context['employ_list']=employ_list'''
    context['total'] = total
    context['list'] = list
    return render(request,'empoll/outputlist.html',context)

def output_the_one_infor(request,searchid,total):
    if(searchid=='xl0058'):
        return render(request, 'empoll/error.html', {'error_msg': '您无法查看该人员的记录','id':0})
    response = HttpResponse(content_type='application/vnd.ms-excel')
    user = get_object_or_404(Employ, employ_ID=searchid)
    list = scorer.objects.filter(scorer_appraisered=searchid)
    strcd=u'attachment;filename='+user.employ_ID+u'.xls'
    response['Content-Disposition'] = strcd

    wb = xlwt.Workbook(encoding='utf-8')
    stradd=str(searchid)+user.employ_name+u'个人分数详情'
    sheet = wb.add_sheet(stradd)
    sheet.col(0).width = 256 * 20
    sheet.col(1).widt= 256 * 20
    sheet.col(2).width= 256 * 20
    sheet.col(3).width= 256 * 20

    # 1st line
    sheet.write(0, 0, '评分人ID')
    sheet.write(0, 1, '被评分人ID')
    sheet.write(0, 2, '分数')
    sheet.write(0, 3, '总分')
    #sheet.write(0, 5, '部门')
    #sheet.write(0, 6, '职位')
    user=get_object_or_404(Employ,employ_ID=searchid)
    row = 1
    for obj in list:
        sheet.write(row, 0, obj.scorer_appraiser)
        sheet.write(row, 1, obj.scorer_appraisered)
        sheet.write(row, 2, obj.scorer_value)
        row = row + 1

    sheet.write(row, 3, total)
    '''
    for usa in Student.objects.all():
        sheet.write(row, 0, usa.Student_xue)
        sheet.write(row, 1, usa.Student_name)
        if (usa.Student_sex):
            sex = "男"
        else:
            sex = "女"
        sheet.write(row, 2, sex)
        sheet.write(row, 3, usa.Student_age)
        sheet.write(row, 4, usa.Student_class)
        sheet.write(row, 5, usa.Student_inday.strftime('%Y-%m-%d'))
        sheet.write(row, 6, usa.Student_major)
        row = row + 1'''

    wb.save(response)
    return response

def output_the_all_infor(request,id):
    user=get_object_or_404(Employ,employ_ID=id)
    if(user.employ_auth>0):
        return render(request,'empoll/error.html',{'error_msg':'您的权限不够','id':id})
    response = HttpResponse(content_type='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment;filename=all_score.xls'
    wb = xlwt.Workbook(encoding='utf-8')
    stradd =u'所有人分数详情'
    sheet = wb.add_sheet(stradd)
    # 1st line
    sheet.col(0).width=256*20
    sheet.col(1).width= 256 * 20
    sheet.col(2).width= 256 * 20
    sheet.col(3).width= 256 * 20
    sheet.col(4).width= 256 * 20

    sheet.write(0, 0, '工号')
    sheet.write(0, 1, '姓名')
    sheet.write(0, 2, '部门')
    sheet.write(0, 3, '职位')
    sheet.write(0, 4, '被评总分')
    # sheet.write(0, 5, '部门')
    # sheet.write(0, 6, '职位')

    row = 1
    for obj in Employ.objects.filter(employ_auth__lte=8, employ_auth__gte=4).order_by('employ_depart'):
        sheet.write(row, 0, obj.employ_ID)
        sheet.write(row, 1, obj.employ_name)
        sheet.write(row, 2, obj.employ_depart)
        sheet.write(row, 3, GENDER_CHOICES_DEPARTnumber[obj.employ_auth])
        if(obj.employ_ID!='xl0058'):
            total=round(getgrade(obj),2)
        else:
            total=round(getsxl(),2)
        sheet.write(row, 4, total)
        row=row+1
    '''
    for usa in Student.objects.all():
        sheet.write(row, 0, usa.Student_xue)
        sheet.write(row, 1, usa.Student_name)
        if (usa.Student_sex):
            sex = "男"
        else:
            sex = "女"
        sheet.write(row, 2, sex)
        sheet.write(row, 3, usa.Student_age)
        sheet.write(row, 4, usa.Student_class)
        sheet.write(row, 5, usa.Student_inday.strftime('%Y-%m-%d'))
        sheet.write(row, 6, usa.Student_major)
        row = row + 1'''

    wb.save(response)
    return response


def set_time(request,id):
    try:
        sday = request.POST['s_day']
        eday = request.POST['e_day']
    except:
        return render(request,'empoll/error.html',{'error_msg':'输入错误,请保证输入时间正确','id':id})
    if(sday>eday):
        return render(request, 'empoll/error.html', {'error_msg': '输入错误,请保证输入时间正确', 'id': id})
    timeo = time.objects.get(id=1)
    timeo.time_start=sday
    timeo.time_end=eday
    timeo.save()
    #添加线程控制
    job_process.sched.shutdown()
    job_process.remove_job()
    job_process.new_job(eday)
    job_process.start()

    return loginwithoutvalite(request,id)



def when_time_to_end_crawler_job():
    print("do something")
    # subprocess.call("python Crawler.py")
'''
job_id=sched.add_job(when_time_to_end_crawler_job, 'cron', hour='8, 12', minute='30')
job_list.append(job_id);'''

def deleteallinformation(request,id):

    user = Employ.objects.get(employ_ID=id)
    if(user.employ_auth!=0):
        return render(request, 'empoll/error.html', {'error_msg': '抱歉您的权限不够', 'id': id})
    else:
        return render(request,'empoll/delete_to_next_year.html',{'id':id});
        return render(request, 'empoll/error.html', {'error_msg': '备份错误请联系管理员', 'id': id})
        return touserlist(request, id)

def GetBackUpCopy(request,id):
    user=Employ.objects.all()
    for user_object in user:
        user_object.employ_has=""
        user_object.save()
    backup_path='/home/python/newtest/'
    os.system('mysqldump -uroot -pmysql book_info > '+backup_path+'book_info_$(date +%Y%m%d_%H%M%S).sql')
    scorer.objects.all().delete()
    return touserlist(request,id)
#



#error

def page_permission_denied(request):
    return render(request, 'empoll/error.html', {'error_msg': '403error', 'id': None})
def page_not_found(request):
    return render(request, 'empoll/error.html', {'error_msg': '404error','id':None})
def page_inter_error(request):
    return render(request, 'empoll/error.html', {'error_msg': '405error', 'id': None})

#问题页面未完全开发
def create(request):
    try:

        title = request.POST['question_title']
        de = request.POST['question_text']
        se = request.POST['question_score']
    except:
        return render(request,'empoll/error.html',{'error_msg':'输入错误,请保证输入完整,若有问题请与管理员联系'})
    else:
        pass



